package com.xindaoapp.framework.activity;

import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.xindaoapp.framework.R;
import com.xindaoapp.framework.api.AddClient;
import com.xindaoapp.framework.api.Address;
import com.xindaoapp.framework.utils.ProgressHUD;

/**
 * ============================================================
 * 
 * 版权 : 新道APP (c) 2014
 * 
 * 作者 : 贺奕凯
 * 
 * 版本 : 1.0
 * 
 * 创建日期 : 2014-7-17 上午10:05:05
 * 
 * 描述 : 登陆界面
 * 
 * 修订历史 ：
 * 
 * ============================================================
 **/
public class HelpActivity extends Activity {
	@ViewInject(R.id.tittle_common_cancel)
	private ImageView tittle_common_cancel;
	@ViewInject(R.id.tittle_common_content)
	private TextView tittle_common_content;
	@ViewInject(R.id.text)
	private EditText text;
	@ViewInject(R.id.go)
	private Button go;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_help);
		tm = (TelephonyManager) this.getSystemService(TELEPHONY_SERVICE);
		ViewUtils.inject(this);
		tittle_common_content.setText("意见反馈");
		tittle_common_cancel.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});

		tittle_common_content = (TextView) findViewById(R.id.tittle_common_content);
		go.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if (!TextUtils.isEmpty(text.getText().toString().trim())) {
					addHelp(text.getText().toString().trim());
				} else {
					Toast.makeText(getApplicationContext(), "请输入反馈内容",
							Toast.LENGTH_SHORT).show();
				}
			}
		});

	}

	private TelephonyManager tm;

	protected void addHelp(String trim) {
		RequestParams params = new RequestParams();
		params.put("phoneType", "android");
		params.put("systemVersion", tm.getDeviceSoftwareVersion());
		params.put("phoneSystem", Build.MODEL);
		params.put("description", trim);
		final ProgressHUD ProgressDialog = ProgressHUD.show(this, "正在提交...",
				true, true, null);
		AddClient.get(Address.HELP, params, new AsyncHttpResponseHandler() {
			@Override
			public void onSuccess(int statusCode, String content) {
				if (null != ProgressDialog && ProgressDialog.isShowing()) {
					ProgressDialog.dismiss();
				}
				Toast.makeText(getApplicationContext(), "您的建议已经提交",
						Toast.LENGTH_SHORT).show();
				super.onSuccess(statusCode, content);
			}

			@Override
			public void onFailure(Throwable error, String content) {
				if (null != ProgressDialog && ProgressDialog.isShowing()) {
					ProgressDialog.dismiss();
				}
				super.onFailure(error, content);
			}
		});
	}
}
